export default {
  namespaced:true,
  state:{
    msgHistory:[],
    oneHistory:{}
  },
  mutations:{
    setMsgHistory(state,message) {
      state.msgHistory = message
      
    },
    setOneHistory(state,id) {
     const findResult =  state.msgHistory.find(item => item.user_id === id)
     if(findResult) {
       state.oneHistory = findResult
     }else {
       state.oneHistory = {
         messages:[]
       }
     }
    
      
    },
    addOneMessage(state,obj) {
      state.oneHistory.messages.push(obj)
    }
    
  },
  actions:{
   async getMessageHistory({commit}) {
     const res = await uni.$http.get('/user/chat/history')
     console.log(res)
     commit('setMsgHistory',res.data.data)
      
    }
  }
}